<?php
/**
 * 银行卡
 * Created by PhpStorm.
 * @User: 王海东
 * @Date: 2018/12/21 15:54
 */

namespace app\adm\controller;

use app\common\model\Bankinfo;

class BankinfoController extends BaseController
{
    /**
     * 银行卡列表
     * @author 王海东
     * @date
     * @return void
     * @throws \Exception
     */
    public function select()
    {
        $in = $this->I([
            [
                "start_time|开始时间",
                null,
                "s",
            ],
            [
                "end_time|截止时间",
                null,
                "s",
            ],
            [
                "name|用户名或手机号",
                null,
                "s",
            ],
            [
                "agent_name|代理商名称",
                null,
                "s",
            ],
            [
                "page|页码",
                DEF_PAGE_NO,
                "d",
            ],
            [
                "pageSize|页幅",
                DEF_PAGE_SIZE,
                "d",
            ],
        ]);

        $b = new Bankinfo();

        $map = [
            'start_time' => $in['start_time'],
            'end_time'   => $in['end_time'],
            'name'       => $in['name'],
            'agent_name' => $in['agent_name'],
        ];

        $data = $b->select(UID, $map, $in['page'], $in['pageSize']);

        rjd($data);
    }

    /**
     * 删除银行卡
     * @author 王海东
     * @date
     * @return void
     * @throws \Exception
     */
    public function delete()
    {
        $in = $this->I([
            [
                "bankId|银行卡id",
                null,
                "d",
                "require",
            ],
        ]);

        $b = new Bankinfo();

        if (!$b->delete($in['id'])) {
            rj(1, '删除失败');
        }

        rj();
    }

    /**
     * 修改银行卡
     * @author 王海东
     * @date
     * @return void
     * @throws \Exception
     */
    public function edit()
    {
        $in = $this->I([
            [
                "id|银行卡id",
                null,
                "d",
                "require",
            ],
            [
                "bankname|银行名称",
                null,
                "s",
                "require",
            ],
            [
                "bank_card_num|银行卡号",
                null,
                "d",
                "require|number",
            ],
            [
                "bank_branch|支行名称",
                null,
                "s",
                "require",
            ],
            [
                "busername|持卡人",
                null,
                "s",
                "require|max:25",
            ],
            [
                "card|身份证号",
                null,
                "s",
                "require|idCard",
            ],
            [
                "mobile|银行预留手机号",
                null,
                "s",
                "require|mobile",
            ],
            [
                "area|开户区域",
                null,
                "s",
            ],
        ]);

        $b = new Bankinfo();
        if (!$b->update($in['id'], $in)) {
            rj(1, '修改失败');
        }

        rj();
    }

    /**
     * 银行卡详细信息
     * @author 王海东
     * @date
     * @return void
     * @throws \Exception
     */
    public function info()
    {
        $in = $this->I([
            [
                "id|银行卡id",
                null,
                "d",
                "require",
            ],
        ]);

        $b = new Bankinfo();

        $data = $b->find($in['id']);

        rjd($data);
    }
}